package org.exeed.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.exeed.dao.PageHistoryMapper;
import org.exeed.entity.PageHistoryEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class PageHistoryService {

    @Autowired
    private PageHistoryMapper pageHistoryMapper;


    public Map selectList(Integer page, Integer size, Long sourceId) {

        Page<PageHistoryEntity> iPage = new Page<>(page, size);
        QueryWrapper<PageHistoryEntity> queryWrapper = new QueryWrapper<>();
//        queryWrapper.select("id", "path", "type", "title", "des", "thumbnail_url", "publish_time", "update_time", "is_publish", "article_type", "pdf_resource_url");
        queryWrapper.eq("source_id", sourceId);
        queryWrapper.orderByDesc("update_time");
        IPage<PageHistoryEntity> list = pageHistoryMapper.selectPage(iPage, queryWrapper);
        Map<String, Object> R = new HashMap<>();
        R.put("page", page);
        R.put("size", size);
        R.put("total", list.getTotal());
        R.put("list", list.getRecords());
        return R;
    }

    public PageHistoryEntity selectById(Long id) {
        return pageHistoryMapper.selectById(id);
    }

}
